home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / pbc23c.arj / FILESORT.BAS < prev    next >
BASIC Source File  |  1994-03-13  |  2KB  |  61 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1994  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7.    TYPE FileName
  8.       Arf AS STRING * 12     ' because TYPE is still pretty brain-dead
  9.    END TYPE
  10.  
  11.    TYPE Partition
  12.       Lft AS INTEGER
  13.       Rht AS INTEGER
  14.    END TYPE
  15.  
  16. SUB FileSort (Array() AS FileName, Elements%)
  17.    DIM x AS STRING * 12
  18.    DIM SortStack(1 TO 16) AS Partition
  19.    S% = 1
  20.    SortStack(1).Lft = 1
  21.    SortStack(1).Rht = Elements%
  22.    DO
  23.       L% = SortStack(S%).Lft
  24.       R% = SortStack(S%).Rht
  25.       S% = S% - 1
  26.       DO
  27.          i% = L%
  28.          j% = R%
  29.          x = Array((L% + R%) \ 2).Arf
  30.          DO
  31.             WHILE Array(i%).Arf < x
  32.                i% = i% + 1
  33.             WEND
  34.             WHILE x < Array(j%).Arf
  35.                j% = j% - 1
  36.             WEND
  37.             IF i% <= j% THEN
  38.                SWAP Array(i%), Array(j%)
  39.                i% = i% + 1
  40.                j% = j% - 1
  41.             END IF
  42.          LOOP UNTIL i% > j%
  43.          IF j% - L% < R% - i% THEN
  44.             IF i% < R% THEN
  45.                S% = S% + 1
  46.                SortStack(S%).Lft = i%
  47.                SortStack(S%).Rht = R%
  48.             END IF
  49.             R% = j%
  50.          ELSE
  51.             IF L% < j% THEN
  52.                S% = S% + 1
  53.                SortStack(S%).Lft = L%
  54.                SortStack(S%).Rht = j%
  55.             END IF
  56.             L% = i%
  57.          END IF
  58.       LOOP UNTIL L% >= R%
  59.    LOOP WHILE S%
  60. END SUB
  61.